package org.example.service.impl;

import io.seata.spring.annotation.GlobalTransactional;
import org.example.entity.User;
import org.example.mapper.UserMapper;
import org.example.service.OpenFeignClient;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private OpenFeignClient openFeignClient;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add() {
        userMapper.addUser(new User("1","2","3"));
        System.out.println("验证事务");
        int a=1/0;
        System.out.println(a);
    }
    @GlobalTransactional
    @Override
    public void getOpenFeignClient() {
        openFeignClient.testSeata();
        add();
    }
}
